package com.xiaoyu.izf.model;

import cn.hutool.core.date.DateUtil;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

@Entity
@Table(name = "merchant_shop_info", schema = "izf", catalog = "")
public class MerchantShopInfo {
    private int id;
    private Integer merchantId;
    private String shopName;
    private String status;
    private String province;
    private String city;
    private String shopAddress;
    private String shopPhone;
    private Timestamp createTime;
    private String shopPic;
    private Integer uid;
    private String regionCode;

    private String createTimeStr;
    private MerchantInfo merchantInfo;
    private UserInfo parUser;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "merchant_id")
    public Integer getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(Integer merchantId) {
        this.merchantId = merchantId;
    }

    @Basic
    @Column(name = "shop_name")
    public String getShopName() {
        return shopName;
    }

    public void setShopName(String shopName) {
        this.shopName = shopName;
    }

    @Basic
    @Column(name = "status")
    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    @Basic
    @Column(name = "province")
    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    @Basic
    @Column(name = "city")
    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @Basic
    @Column(name = "shop_address")
    public String getShopAddress() {
        return shopAddress;
    }

    public void setShopAddress(String shopAddress) {
        this.shopAddress = shopAddress;
    }

    @Basic
    @Column(name = "shop_phone")
    public String getShopPhone() {
        return shopPhone;
    }

    public void setShopPhone(String shopPhone) {
        this.shopPhone = shopPhone;
    }

    @Basic
    @Column(name = "create_time")
    public Timestamp getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "shop_pic")
    public String getShopPic() {
        return shopPic;
    }
    public void setShopPic(String shopPic) {
        this.shopPic = shopPic;
    }

    @Basic
    @Column(name = "uid")
    public Integer getUid() {
        return uid;
    }
    public void setUid(Integer uid) {
        this.uid = uid;
    }

    @Basic
    @Column(name = "region_code")
    public String getRegionCode() {
        return regionCode;
    }
    public void setRegionCode(String regionCode) {
        this.regionCode = regionCode;
    }

    @Transient
    public String getCreateTimeStr() {
        return DateUtil.formatDateTime(createTime);
    }
    public void setCreateTimeStr(String createTimeStr) {
        this.createTimeStr = createTimeStr;
    }

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, optional = true)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "merchant_id", referencedColumnName = "id", insertable = false, updatable = false,foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    public MerchantInfo getMerchantInfo() {
        return merchantInfo;
    }
    public void setMerchantInfo(MerchantInfo merchantInfo) {
        this.merchantInfo = merchantInfo;
    }

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, optional = true)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "uid", referencedColumnName = "id", insertable = false, updatable = false,foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    public UserInfo getParUser() {
        return parUser;
    }
    public void setParUser(UserInfo parUser) {
        this.parUser = parUser;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MerchantShopInfo that = (MerchantShopInfo) o;
        return id == that.id &&
                Objects.equals(merchantId, that.merchantId) &&
                Objects.equals(shopName, that.shopName) &&
                Objects.equals(status, that.status) &&
                Objects.equals(province, that.province) &&
                Objects.equals(city, that.city) &&
                Objects.equals(shopAddress, that.shopAddress) &&
                Objects.equals(shopPhone, that.shopPhone);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, merchantId, shopName, status, province, city, shopAddress, shopPhone);
    }

    @Override
    public String toString() {
        return "MerchantShopInfo{" +
                "id=" + id +
                ", merchantId=" + merchantId +
                ", shopName='" + shopName + '\'' +
                ", status='" + status + '\'' +
                ", province='" + province + '\'' +
                ", city='" + city + '\'' +
                ", shopAddress='" + shopAddress + '\'' +
                ", shopPhone='" + shopPhone + '\'' +
                ", createTime=" + createTime +
                ", shopPic='" + shopPic + '\'' +
                ", createTimeStr='" + createTimeStr + '\'' +
                ", merchantInfo=" + merchantInfo +
                '}';
    }
}
